﻿@{
    ViewBag.Title = "后台管理";
    string navDataUrl = Url.Action("GetMenuData");
}
@section style{
}
<div class="mini-layout" style="width:100%;height:100%;">
    <div title="north" region="north" class="app-header" bodyStyle="overflow:hidden;" height="80" showHeader="false" showSplit="false">
        <h3 style="margin-left: 30px; color: #ffffff; margin-top: 25px;">XXX管理系统</h3>
        <div style="position:absolute;top:18px;right:10px;">
            <a class="mini-button mini-button-iconTop" iconCls="icon-close" onclick="onClick" plain="true">退出</a>
        </div>
    </div>
    <div showHeader="false" region="south" style="border:0;text-align:center;" height="25" showSplit="false">
        Copyright © Seamusic 2015 - @DateTime.Now.Year
    </div>
    <div region="west" title="导航菜单" showHeader="true" bodyStyle="padding-left:1px;" showSplitIcon="true" width="230" minWidth="100" maxWidth="350">
        <!--OutlookMenu-->
        <div id="leftTree" class="mini-outlookmenu" onitemselect="onNodeSelect"
             idField="id" parentField="pid" textField="text" borderStyle="border:0">
        </div>
        @*<ul id="leftTree" class="mini-tree" style="width:100%;height:100%;" showTreeIcon="true" textField="text" idField="id" resultAsTree="false" onnodeselect="onNodeSelect"></ul>*@
    </div>
    <div title="center" region="center" style="border:0;" bodyStyle="overflow:hidden;">
        <div id="mainTabs" class="mini-tabs" activeIndex="0" style="width:100%;height:100%;"
             onactivechanged="onTabsActiveChanged">
            <div title="系统概览">
                <iframe onload="onIFrameLoad(this);" src="@Url.Action("Welcome")" id="mainframe" frameborder="0" name="main" style="width:100%;height:100%;" border="0"></iframe>
            </div>
        </div>
    </div>
</div>

@section footer{
    <script src="~/Scripts/miniui/miniui.min.js"></script>
    <script type="text/javascript">
        function GetParams(url, c) {
            if (!url) url = location.href;
            if (!c) c = "?";
            url = url.split(c)[1];
            var params = {};
            if (url) {
                var us = url.split("&");
                for (var i = 0, l = us.length; i < l; i++) {
                    var ps = us[i].split("=");
                    params[ps[0]] = decodeURIComponent(ps[1]);
                }
            }
            return params;
        }
        function GetUI(url) {
            var ss = url.split("\/");
            url = ss[ss.length - 1];
            ss = url.split(".");
            var ui = ss[0];
            return ui;
        }

        function onIFrameLoad(iframe) {
            var ui = "";
            try {
                var url = iframe.contentWindow.location.href;
                ui = GetUI(url);
            } catch (e) {
            }
            if (ui && ui != "overview") {
                //window.location = "index.html#ui=" + ui;
            }
        }

        var tree = null;
        $(function () {
            var url = window.location.href;
            if (url.indexOf("index.html") === -1) {
                if (parent === window) {
                    var ui = GetUI(location.href);
                    //window.location = "index.html#ui=" + ui;
                }
            } else {
                var params = GetParams(location.href, "#");
                console.log(params);
                if (params.ui) {
                    var frame = document.getElementById("mainframe");
                    //frame.src = params.ui + ".html";
                }
            }

            mini.parse();
            tree = mini.get("leftTree");
            $.getJSON("@navDataUrl", function (data) {
                if (data.length == 0) {
                    return;
                }
                tree.setData(data);
            });
        });

        function showTab(node) {
            if (node.url == null) {
                return;
            }
            var tabs = mini.get("mainTabs");
            var id = "tab$" + node.id;
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab._nodeid = node.id;
                tab.name = id;
                tab.title = node.text;
                tab.showCloseButton = true;
                tab.url = node.url;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
            //tabs.reloadTab(tab);
        }

        function showNewTab(url, name) {
            if (url == null || url === "") {
                return;
            }

            var tabs = mini.get("mainTabs");
            var id = "tab$" + url;
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab._nodeid = id;
                tab.name = name;
                tab.title = name;
                tab.showCloseButton = true;
                tab.url = url;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }

        function onNodeSelect(e) {
            var node = e.item;
            var isLeaf = e.isLeaf;
            if (node.url) {
                showTab(node);
            }
        }

        function onTabsActiveChanged(e) {
            var tabs = e.sender;
            var tab = tabs.getActiveTab();
            if (tab && tab._nodeid) {
                //var node = tree.getNode(tab._nodeid);
                //var treeNode = tree.getSelected();
                //if (node && treeNode && treeNode.uid === node.uid) {
                //    tree.selectNode(node);
                //}
            }
        }
    </script>
}
